export default {

  methods: {
    handleAdd (options) {
      if (!this.hideSideBar) {
        this.hideSideBar = true
      }
      const hasOther = options.some(i => i.id.indexOf('Custom') === -1 && i.id.indexOf('Template') === -1)

      if (this.$refs['filter-condition'] && !hasOther) {
        this.$refs['filter-condition'].tab = true
      }

      if (!hasOther) {
        this.$root.eventBus.$emit('bus:add')
      }
    },

    getTime (data = {}) {
      const {
        from = '',
        to = ''
      } = data
      if (from.length > 0 || to.length > 0) {
        return [from, to]
      }

      return null
    },

    handleChangeQuickFilter (record = {}) {
      const {
        id,
        filterJson
      } = record
      try {
        const {
          get
        } = this._
        let {
          filter = {}, integratin = [], order = []
        } = filterJson
        this.$nextTick(async () => {
          if (id.indexOf('Custom') !== -1) {
            this.recordFilterType = 'Custom'
          }
          if (id.indexOf('Template') !== -1) {
            this.recordFilterType = 'Template'
          }
          this.$refs['sort-condition'].clomu_sort = Object.assign({}, this.$refs['sort-condition'].$options.data().clomu_sort, order[0])
          this.$refs['sort-condition'].sort_order = !get(order, '[0].sort') ? false : get(order, '[0].sort') === 'DESC'
          this.$refs['filter-condition'].filterForm = Object.assign({}, this.$refs['filter-condition'].$options.data().filterForm, filter)
          this.$refs['integration-condition'].integratinSelected = integratin
          this.filterProject.integrationGroup = this.$refs['integration-condition'].integratinSelected
          this.filterProject.filter = this.$refs['filter-condition'].filterForm
          this.filterProject.order = [this.$refs['sort-condition'].clomu_sort]
          this.$refs['filter-condition'].filterForms.createdDateModel = this.getTime(get(filter, 'createDate', {}))
          this.$refs['filter-condition'].filterForms.LastSyncedDateModel = this.getTime(get(filter, 'lastSyncDate', {}))
          this.$refs['filter-condition'].filterForms.lastModifiedDateModel = this.getTime(get(filter, 'updateDate', {}))
          this.$refs['filter-condition'].dataSetFilterNum()

          if (window.CardListSource) window.CardListSource()
          await this.cardQuery(null, null, true)
          // if (this.$refs['no-integration']) {
          //   this.$refs['no-integration'].refresh()
          // }
        })
      } catch (error) {
        if (window.CardListSource) window.CardListSource()
        this.cardQuery(null, null, true)
        // if (this.$refs['no-integration']) {
        //   this.$refs['no-integration'].refresh()
        // }
      }
    }

  }

}
